<template>
	<view class="myqianbao">
		<headertop title="我的钱包" :back1="back1"></headertop>
		<view class="myqianbaoback">

		</view>
		<view class="boxcon">
			<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11452@2x.png" class="boxconback" mode=""></image>
			<view class="texts">
				<view class="t1">
					当前余额
				</view>
				<view class="jigae">
					<span style="font-size: 28rpx;">￥</span>
					<span>{{totalmoney}}</span>
				</view>
				<view class="btn1" @click="gopage()">
					去充值
				</view>
			</view>
		</view>
		<view class="xiaofeibox">
			<view class="xiaofeibox_center">
				<view class="titlebox">
					<span>消费记录</span>
					<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Mask group@2x.png" class="xhx" mode=""></image>
				</view>
				<view class="itemlist">
					<view class="msgicon" v-if="!list.length">
						<image src="/static/微信图片_20250514232056.png" mode="widthFix"></image>
						<view class="msgtext">
							暂无订单
						</view>
					</view>
					<view class="itembox" v-for="(item,index) in list" :key="index">
						<view class="leftbox">
							<view class="leftbox_t1">
								{{item.memo}}
							</view>
							<view class="leftbox_t2">
								{{timestampfun(item.createtime*1000)}}
							</view>
						</view>
						<view :class="item.dtype==1?'rightnum':'rightnum1'">
							{{item.dtype==1?'+':'-'}}{{item.money}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import headertop from '@/components/header.vue'
	import {
		onLoad,
		onPageScroll
	} from "@dcloudio/uni-app";
	import {
		walletlog
	} from '@/api/my.js'
	import {
		ref,
		reactive
	} from 'vue'
	const totalmoney = ref('')
	const query = reactive({
		page: 1,
		limit: 10
	})
	const lastpage = ref(0)
	const list = ref([])
	onLoad(() => {
		init()
	})

	async function init() {
		const res = await walletlog(query)
		if (res.data.code == 1) {
			lastpage.value = res.data.data.lastpage
			list.value.push(...res.data.data.list)
			totalmoney.value = res.data.data.money
		}
	}
	onPageScroll((e) => {
		if (e.scrollTop > 100) {
			back1.value = '#84BD78'
		} else {
			back1.value = ''
		}
		if (lastpage.value > query.page) {
			query.page++
			init()
		}
	})

	function gopage() {
		uni.navigateTo({
			url: '/sub_my/my/chongzhi'
		})
	}

	function timestampfun(time) {
		const date = new Date(time);
		const year = date.getFullYear();
		const month = String(date.getMonth() + 1).padStart(2, "0");
		const day = String(date.getDate()).padStart(2, "0");
		const hours = String(date.getHours()).padStart(2, "0");
		const minutes = String(date.getMinutes()).padStart(2, "0");
		const seconds = String(date.getSeconds()).padStart(2, "0");
		const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		return formattedDate;
	}
</script>
<style lang="scss">
	.msgicon {
		width: 532rpx;
		margin: 100rpx auto;
		overflow: hidden;
	
		.msgtext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #4E5969;
			text-align: center;
			width: 100%;
			margin-top: -30rpx;
		}
	
		image {
			width: 532rpx;
		}
	}
	.myqianbao {
		width: 100%;
		overflow: hidden;
		position: relative;

		.myqianbaoback {
			width: 750rpx;
			height: 660rpx;
			background: linear-gradient(117deg, #84BD78 75%, #75B568 100%);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			position: absolute;
			z-index: -1;
		}

		.xiaofeibox {
			width: 100%;
			background: #FFFFFF;
			box-shadow: 0rpx -4rpx 8rpx 0rpx #63AC54;
			border-radius: 48rpx 48rpx 0rpx 0rpx;
			overflow: hidden;
			z-index: 999;

			&_center {
				width: 686rpx;
				overflow: hidden;
				margin: auto;
				margin-top: 32rpx;

				.itemlist {
					width: 100%;
					margin-top: 18rpx;
					overflow: hidden;

					.itembox {
						width: 686rpx;
						height: 142rpx;
						background: #F2F3F5;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						margin-bottom: 24rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.rightnum1 {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 36rpx;
							color: #1D2129;
							margin-right: 32rpx;
						}

						.rightnum {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 36rpx;
							color: #7EBC79;
							margin-right: 32rpx;
						}

						.leftbox {
							width: 252rpx;
							margin-left: 32rpx;

							&_t1 {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 28rpx;
								color: #1D2129;
							}

							&_t2 {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #86909C;
								margin-top: 22rpx;
							}
						}
					}
				}

				.titlebox {
					width: 128rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 32rpx;
					position: relative;
					color: #1D2129;
					display: flex;
					flex-direction: column;
					align-items: center;

					.xhx {
						width: 100%;
						height: 36rpx;
						margin: auto;
						position: absolute;
						bottom: -30%;
					}
				}
			}
		}

		.boxcon {
			width: 686rpx;
			height: 358rpx;
			margin: auto;
			margin-top: 172rpx;
			position: relative;
			z-index: 999;
			overflow: hidden;

			.boxconback {
				position: absolute;
				z-index: -1;
				width: 686rpx;
				height: 358rpx;
			}

			.texts {
				margin-top: 100rpx;
				margin-left: 54rpx;
				overflow: hidden;

				.t1 {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 32rpx;
					color: #4E5969;
				}

				.jigae {
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 56rpx;
					color: #1D2129;
					margin-top: 17rpx;
				}

				.btn1 {
					width: 162rpx;
					height: 56rpx;
					background: #FFE71B;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					text-align: center;
					line-height: 56rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #1D2129;
					margin-top: 12rpx;
				}
			}
		}
	}
</style>